package com.openatc.agent.service;

import com.openatc.agent.model.VipRouteDeviceStatus;
import com.openatc.agent.model.VipRouteExecute;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author ：zhangwenchao
 * @date ：Created in 2024/4/23 下午5:22
 * @description：VipRouteExecuteDao
 * @modified By：
 * @version: $
 */

@Service
public class VipRouteExecuteDao {
    public List<VipRouteExecute> onExcuteDevlist = new CopyOnWriteArrayList<>();

//    public VipRouteExecute getByAgentid(String agentid) {
//        for(VipRouteExecute vipRouteExecute : onExcuteDevlist){
//            if(vipRouteExecute.getAgentid().equals(agentid))
//                return vipRouteExecute;
//        }
//        return null;
//    }

//    public VipRouteDeviceStatus getStatusByAgentid(String agentid) {
//        VipRouteExecute execute = getByAgentid(agentid);
//        if( execute == null) return null;
//        return execute.getStatus();
//    }

    public VipRouteDeviceStatus getStatusByRouteidAndAgentid(int routeid, String agentid) {
        for(VipRouteExecute vipRouteExecute : onExcuteDevlist){
            if(vipRouteExecute.getViprouteid() == routeid && vipRouteExecute.getAgentid().equals(agentid))
                return vipRouteExecute.getStatus();
        }
        return null;
    }

    public boolean contains(String agentid) {
        for(VipRouteExecute vipRouteExecute : onExcuteDevlist){
            if(vipRouteExecute.getAgentid().equals(agentid))
                return true;
        }
        return false;
    }

    public boolean containsRoute(int routeid) {
        for(VipRouteExecute vipRouteExecute : onExcuteDevlist){
            if(vipRouteExecute.getViprouteid() == routeid)
                return true;
        }
        return false;
    }

    public void add(VipRouteExecute vipRouteExecute) {
        onExcuteDevlist.add(vipRouteExecute);
    }

    public void remove(String agentid) {
        for(VipRouteExecute vipRouteExecute : onExcuteDevlist){
            if(vipRouteExecute.getAgentid().equals(agentid))
                onExcuteDevlist.remove(vipRouteExecute);
        }
    }


}
